package viz_main;

import java.awt.Color;

import processing.core.PApplet;
import view.V_DisplayObject;

public class ScatterPlotPoint extends V_DisplayObject
{
  private boolean selected = false;
  private float opacity = 1.0f;
  private String name;
  private float offX;
  private float offY;
  
  public ScatterPlotPoint(float xVal, float yVal, float sz, int c)
  {
    init(xVal,yVal, Math.max(sz,1), Math.max(sz,1));
    this.setBGColor(c);
  }
  
  public ScatterPlotPoint(float xVal, float yVal)
  {
    init(xVal,yVal, 1, 1);
    this.setBGColor(new Color(0,0,0));
  }
  
  public void setOpacity(float val) {
    opacity = val;
  }
  
  public void setName(String nm) {
    name = nm;
  }
  
  public void setSize(float val) {
    xSize = val;
    ySize = val;
  }
  
  public void display(PApplet p) 
  {
    if(visible)
    {
      if(selected) {
    	  p.fill(Color.MAGENTA.getRGB());
	  }
      else {
    	  p.fill(bgColor >> 16 & 0xFF, bgColor >> 8 & 0xFF, bgColor & 0xFF, (bgColor >> 24 & 0xFF)*opacity);
      }
      p.noStroke();
      p.ellipse(xLoc, yLoc, xSize, ySize);
    }
  }
  
  public void display(float offsetX, float offsetY, PApplet p) // draw the point trusting that the gridView will manage its local position
  {
    if(visible)
    {
      if(selected) {
      	  p.fill(Color.MAGENTA.getRGB());
  	  }
      else {
      	  p.fill(bgColor >> 16 & 0xFF, bgColor >> 8 & 0xFF, bgColor & 0xFF, (bgColor >> 24 & 0xFF)*opacity);
      }
      p.noStroke();
      p.ellipse(offsetX, offsetY, xSize, ySize);
      offX = offsetX;
      offY = offsetY;
    }
  }
  
  public boolean checkOver(float mX, float mY)
  {
    if(mX > offX-(xSize/2) && mX < offX+(xSize/2)) {
      if(mY > offY-(ySize/2) && mY < offY+(ySize/2)) {
        return true;
      }
    }
    return false;
  }
  
  public void setSelected(boolean val)
  {
    selected = val;
  }
}
